<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search ref="search"  :config="searchConfig" @search="search" @getHeight="getHeight"/>

    <!-- 操作按钮区域 -->
    <div class='page_table'>
      <vxe-grid
        ref='xGrid'
        :border='true'
        :resizable='true'
        :showOverflow='true'
        size='mini'
        :loading='loading'
        :height='pageHeight-seachHeight-94'
        :align='left'
        :columns='columns'
        :data='dataSource'
        :toolbar-config="tableToolbar"
        :checkbox-config="{ trigger: 'row'}"
        @checkbox-change='selectChangeEvent'
        @checkbox-all="selectChangeEvent"
      >
        <template #toolbar_buttons>
          <div class='table-operator'>
            <a-button @click='handleAdd' type='primary'>新增</a-button>
            <a-button @click='batchDel' type='primary'>删除</a-button>
            <a-button @click='handleAdd' type='primary'>导入</a-button>
            <a-button @click='handleAdd' type='primary'>导出</a-button>
          </div>
        </template>

        <template #detail='{ row,rowIndex }'>
          <a @click='handleDetail(row)'>{{ row.bigDateCode }}</a>
        </template>
        <!-- <template #customerCode='{ row,rowIndex }'>
          <a @click="handleEdit(row, '详情', true, true)">{{ row.customerCode }}</a>
        </template> -->

        <template  #action='{ row,rowIndex }'>
          <a @click='handleEdit(row)'>编辑</a>
          <a-divider type="vertical"/>
          <a href='javascript:' @click='handleBusiness("大日期分配",row)'>日志</a>
        </template>
        <template #update="{ row }">
          <a-switch :checked="row.status" size="small" @change="handleStatus(row,$event,)"/>
        </template>
        <template #pager>
          <vxe-pager
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :currentPage.sync='ipagination.current'
            :page-size.sync='ipagination.pageSize'
            :total='ipagination.total'
            :pageSizes='ipagination.pageSizeOptions'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>

    </div>
    <!-- table区域-end -->
    <business-log ref='businessLog'></business-log>

    <!-- 表单区域 -->
    <big-date-modal ref="modalForm" @ok="modalFormOk"></big-date-modal>
  </a-card>
</template>

<script>
  import bigDateModal from './modules/bigDateModal'
  import { PageListMixin } from '@/mixins/PageListMixin'
  import Vue from 'vue'
  import { getAction } from '@/api/manage'
  import search from '@comp/view/base-crud/search/Search'
  import { filterObj } from '@/utils/util'

  //高级查询modal需要参数

  export default {
    name: 'bigDateList',
    mixins: [PageListMixin],
    components: {
      bigDateModal,
      search
    },
    // priceAdd
    data() {
      return {
        description: '大日期分配',
        //字典数组缓存
        sexDictOptions: [],
        searchConfig:[
          {
            // label:'订单编号',
            type:'input',
            name:'bigDateCode',
            placeholder:'大日期编号',
          },
          {
            type:'input',
            name:'customerCode',
            placeholder:'经销商编号',
          },
          {
            type:'input',
            name:'customerName',
            placeholder:'经销商名称',
          },
          {
            type: 'j-select',
            name: 'status',
            placeholder: '请选择状态',
            dictCode:'gift_status'
          },
          {
            type:'input',
            name:'orgName',
            placeholder:'所属组织',
          },
          {
            type: 'date-range', //范围选择
            range: ['startDate', 'endDate'],
            name: 'policyDate',
            format: 'YYYY-MM-DD',
            placeholder: ['开始时间', '结束时间']
          },
          {
            type:'input',
            name:'productCode',
            placeholder:'产品编号',
          },
          {
            type:'input',
            name:'productName',
            placeholder:'产品名称',
          },
        ],
        //表头
        columns: [],
        //列设置
        settingColumns: [],
        //列定义  表格改这儿
        defColumns: [
          { type: 'checkbox', width: 60, fixed: 'left' },
          {
            title: '大日期编号',
            align: 'center',
            minWidth: 100,
            field: 'bigDateCode',
            slots: {
              default: 'detail'
            }
          },
          {
            title: '经销商编号',
            align: 'center',
            minWidth: 100,
            field: 'customerCode'
          },
          {
            title: '经销商名称',
            align: 'center',
            minWidth: 170,
            field: 'customerName'
          },
          {
            title: '所属组织',
            align: 'center',
            minWidth: 120,
            field: 'orgName'
          },
          {
            title: '政策时间',
            align: 'center',
            minWidth:170,
            field: 'policyDate'
          },
          {
            title: '产品编号',
            align: 'center',
            minWidth: 100,
            field: 'productCode'
          },
          {
            title: '产品名称',
            align: 'center',
            minWidth: 170,
            field: 'productName'
          },
          {
            title: '批次日期',
            align: 'center',
            minWidth:170,
            field: 'batchDate'
          },
          {
            title: '产品总数量',
            align: 'center',
            minWidth: 100,
            field: 'productCount'
          },
          {
            title: '已使用数量',
            align: 'center',
            minWidth: 100,
            field: 'useCount'
          },
          {
            title: '剩余数量',
            align: 'center',
            minWidth: 100,
            field: 'surplusCount'
          },
          {
            title: '备注',
            align: 'center',
            minWidth: 100,
            field: 'remarks'
          },
          {
            title: '创建人',
            align: 'center',
            minWidth: 100,
            field: 'createName'
          },
          {
            title: '创建时间',
            align: 'center',
            minWidth: 150,
            field: 'createTime'
          },
          {
            title: '更新人',
            align: 'center',
            minWidth: 100,
            field: 'updateName'
          },
          {
            title: '更新时间',
            align: 'center',
            minWidth: 150,
            field: 'updateTime'
          },
          {
            title: '状态',
            align: 'left',
            field: 'status',
            fixed: 'right',
            minWidth: 80,
            slots: { default: 'update' }

          },
          {
            title: '操作',
            width: 150,
            // fixed: 'action',
            align: 'center',
            fixed: 'right',
            slots: { default: 'action'}
          },
        ],
        url: {
          list: window._CONFIG['domianPromotion'] + '/bigdateassign/dmsBigDateAssign/findPageList',
          detail: window._CONFIG['domianPromotion'] + '/bigdateassign/dmsBigDateAssign/getInfo',
          delete: window._CONFIG['domianPromotion'] + '/bigdateassign/dmsBigDateAssign/delete',
          startOrStopUrl: window._CONFIG['domianPromotion'] + "/bigdateassign/dmsBigDateAssign/updateStatus",
           deleteBatch:  window._CONFIG['domianPromotion'] +'/bigdateassign/dmsBigDateAssign/deleteBatch',
          exportXlsUrl: '/test/cn-formDemo/exportXls'

        }

      }
    },

    methods: {
      handleAdd() {
        this.$refs.modalForm.add()
        this.$refs.modalForm.title = '新增大日期'
        this.$refs.modalForm.disableSubmit = false
        this.$refs.modalForm.disableEdit = false
      },
      handleEdit: function(row) {
        this.$refs.modalForm.edit(row)
        this.$refs.modalForm.title = '编辑大日期'
        this.$refs.modalForm.disableSubmit = false
        this.$refs.modalForm.disableEdit = true //编辑不能修改

      },
      getQueryParams() {
        //高级查询器
        let sqp = {}
        if (this.superQueryParams) {
          sqp['superQueryParams'] = encodeURI(this.superQueryParams)
          sqp['superQueryMatchType'] = this.superQueryMatchType
        }
        var param = Object.assign(sqp, this.queryParam, this.isorter, this.filters)

        param.field = this.getQueryField()
        param.current = this.ipagination.current
        param.size = this.ipagination.pageSize
        delete param.birthdayRange //范围参数不传递后台
        return filterObj(param)
      },
      // initDictConfig() {
      //   console.log("--我才是真的方法!--")
      //初始化字典 - 性别
      // initDictOptions('sex').then((res) => {
      //   if (res.success) {
      //     this.sexDictOptions = res.result;
      //   }
      // });
      // },
      //列设置更改事件
      onColSettingsChange(checkedValues) {
        var key = this.$route.name + ':colsettings'
        Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
        this.settingColumns = checkedValues
        const cols = this.defColumns.filter(item => {
          if (item.key == 'rowIndex' || item.dataIndex == 'action') {
            return true
          }
          if (this.settingColumns.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns = cols
      },
      initColumns() {
        //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
        //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

        var key = this.$route.name + ':colsettings'
        let colSettings = Vue.ls.get(key)
        if (colSettings == null || colSettings == undefined) {
          let allSettingColumns = []
          this.defColumns.forEach(function(item, i, array) {
            allSettingColumns.push(item.dataIndex)
          })
          this.settingColumns = allSettingColumns
          this.columns = this.defColumns
        } else {
          this.settingColumns = colSettings
          const cols = this.defColumns.filter(item => {
            if (item.key == 'rowIndex' || item.dataIndex == 'action') {
              return true
            }
            if (colSettings.includes(item.dataIndex)) {
              return true
            }
            return false
          })
          this.columns = cols
        }
      }
    },
    created() {
      this.initColumns()
    }

  }
</script>
<style scoped>
  /*@import '~@assets/less/common.less';*/
</style>